/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 62536
 * Date: 2024-06-11
 * Time: 8:50
 */
public class Solution {
    public int massage(int[] nums) {
        int n = nums.length;
        if(n == 0){
            return 0;
        }
        //f表代表该数被选的情况，g表代表该数没有被选的情况
        int[] f = new int[n];
        int[] g = new int[n];
        f[0] = nums[0];

        for (int i = 1; i < n; i++) {
            f[i] = g[i-1] + nums[i];
            g[i] = Math.max(f[i-1],g[i-1]);
        }

        return Math.max(f[n-1], g[n-1]);
    }
}
